<?php

namespace app\model;

use think\Model;

class Prize extends Model
{
    // 所有奖品
    public function all()
    {
        return $this->select();
    }

    // 新增奖品
    public function add($name, $icon, $odds, $count)
    {
        $this->save([
            'name' => $name,
            'icon' => $icon,
            'odds' => $odds,
            'count' => $count,
        ]);
    }

    // 修改奖品
    public function upd($data)
    {
        $info = $this->find($data['id']);
        if (!empty($info)) {
            $save = [];

            foreach ($data as $key => $val) {
                if (!empty($val)) {
                    $save[$key] = $val;
                }
            }

            $info->save($save);
        }
    }

    // 删除奖品
    public function del($id)
    {
        $this->destroy($id);
    }
}
